package logic

import (
	"context"
	"gitee.com/Cauchy_AQ/vxopen/api/internal/svc"
	"gitee.com/Cauchy_AQ/vxopen/api/internal/types"
	"gitee.com/Cauchy_AQ/vxopen/pkg/jwt"
	"gitee.com/Cauchy_AQ/vxopen/rpc/transform/transform"
	"github.com/zeromicro/go-zero/core/logx"
)

type UserPasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserPasswordLogic {
	return &UserPasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserPasswordLogic) UserPassword(req *types.UserPasswordReq) (resp *types.UserPasswordResp, err error) {
	myClaims := l.ctx.Value("MyClaims").(jwt.MyClaims)

	_, err = l.svcCtx.Transformer.UserPassword(context.Background(), &transform.UserPasswordReq{
		OldPassword: req.OldPassword,
		NewPassword: req.NewPassword,
		Openid:      myClaims.OpenId,
		Mobile:      myClaims.Mobile,
	})
	if err != nil {
		return nil, err
	}
	return nil, nil
}
